<!-- <template>
	<div class="sys-org-container">

		<div style="width: 100%;">
			<screeningCondition :inquireInfo="state.inquireInfo" @getChildren="getData">
				<el-button type="primary" icon="ele-Plus" @click="openAddOrg">
					新增
				</el-button>
			</screeningCondition>
		</div>

		<el-card class="full-table" shadow="hover" style="margin-top: 5px">
			<el-table :data="state.Data" v-loading="state.loading" border highlight-current-row
				:header-cell-style="{ background: 'var(--el-color-primary)', height: '55px', color: '#fff', border: '1px solid #fff', fontWeight: 'bold', fontSize: '13px' }"
				:cell-style="{ padding: '2px' }">
				<el-table-column type="index" label="序号" align="center"></el-table-column>
				<el-table-column label="状态" align="center" width="70">
					<template #default="scope">
						<el-tag type="success" v-if="scope.row.whStatus === 0">启用</el-tag>
						<el-tag type="danger" v-else>停用</el-tag>
					</template>
				</el-table-column>
				<el-table-column prop="whName" label="仓库名称" header-align="center" align="center" width="140"
					show-overflow-tooltip />
				<el-table-column label="类型" header-align="center" width="70" align="center" show-overflow-tooltip>
					<template v-slot="scope">
						{{ scope.row.whType === 1 ? '线边仓' : '工厂仓' }}
					</template>
				</el-table-column>
				<el-table-column prop="whAddress" label="仓库地址" width="200" align="center" show-overflow-tooltip />
				<el-table-column prop="currentRegionCount" label="区域数量" width="70" align="center"
					show-overflow-tooltip />
				<el-table-column prop="currentStorageCount" label="库位总数" width="70" align="center"
					show-overflow-tooltip />
				<el-table-column prop="currentStorageCountUsAble" label="可用库位" width="70" align="center"
					show-overflow-tooltip />
				<el-table-column prop="whRemake" label="备注" header-align="center" show-overflow-tooltip />
				<el-table-column prop="createUserName" label="新增人" width="100" align="center" show-overflow-tooltip />
				<el-table-column prop="updateUserName" label="更新人" width="100" align="center" show-overflow-tooltip />
				<el-table-column label="操作" width="150" fixed="right" align="center" show-overflow-tooltip>
					<template #default="scope">
						<el-button size="small" type="primary" @click="openEdit(scope.row)"> 编辑 </el-button>
						<el-button size="small" type="danger" @click="handleDelete(scope.row)"
							v-auth="'warehouse:delete'"> 删除 </el-button>
					</template>
				</el-table-column>
			</el-table>

			<el-pagination v-model:current-page="state.queryParams.page" v-model:page-size="state.queryParams.pageSize"
				:page-sizes="[10, 20, 30, 40]" layout="total, sizes, prev, pager, next, jumper" :total="state.total"
				@size-change="handleSizeChange" @current-change="handleCurrentChange" :small="true" />
		</el-card>

		<EditPos ref="editPosRef" :title="state.editPosTitle" @handleQuery="getData" />
	</div>
</template>
<script lang="ts" setup name="Warehouse">
import { onMounted, reactive, ref, toRaw, nextTick } from 'vue';
import { ElMessageBox, ElMessage } from 'element-plus';
import { getAPI } from '/@/utils/axios-utils';
import { WmsApi } from '/@/api/wh';
import EditPos from '/@/views/system/warehouse/component copy/editPos.vue';
import screeningCondition from "/@/views/tools/screeningCondition.vue";
import { SysDictDataApi } from '/@/api-services';

//新增修改ref
const editPosRef = ref()
const state = reactive({

	editPosTitle: '',
	loading: false,
	//列表展示数据
	Data: [],
	value: {},
	queryParams: {
	
		page: 1,
		pageSize: 20,
		whNum:'',
		whName:''
	},
	queryParams1: {
		page: 1,
		pageSize: 20,
	},
	allAreaData: [],
	//编辑集合的对象
	ruleForm: {
		"whType": undefined,
		"whAddress": "",
		"whStatus": 0,
		"whRemake": "",
		"whNum": "",
		"whName": ""
	},
	//当前仓库底下的区域
	currentChildrenData: [],
	//新增集合的对象
	ruleForm2: {},
	total: 0,
	totalTwo: 0,
	totalThree: 0,
	inquireInfo: [
		{
			label: "仓库编号",
			value: "",
			key: "whNum",
			options: [],
			type: "input",
		},
		{
			label: "仓库名称",
			value: "",
			key: "whName",
			options: [],
			type: "input",
		},
		{
			label: "仓库类型",
			value: "",
			key: "whType",
			options: [
				{
					value: 0,
					label: "工厂仓",
				},
				{
					value: 1,
					label: "线边仓",
				},
			],
			type: "select",
		}
	],
});
onMounted(async () => {
	var res = await getAPI(SysDictDataApi).apiSysDictDataDataListCodeGet('w_type');
	console.log(res);
	state.inquireInfo[2].options = res.data.result?.map((item) => ({
		value: item.code,
		label: item.name
	}));
	console.log(state.inquireInfo[2].options);

	getData(state.queryParams);

})
//查询,value的值是组件事件子组件传递的值
const getData = (value: any) => {
	state.value = value;
	let params = {
		page: state.queryParams.page,
		pageSize: state.queryParams.pageSize,
		whNum: value?.whNum ?? null,
		whName: value?.whName ?? null,
		whType: value?.whType ?? null
	};
	WmsApi().WhPagePost(params)
		.then(function (res) {
			state.Data = res.data.result.items;
			state.total = res.data.result.total;
		})
		.catch(function (error) {
			console.log(error);
		});
}


//删功能
const handleDelete = (row: any) => {
	ElMessageBox.confirm(`确定删除该仓库：【${row.whName}】?`, '提示', {
		confirmButtonText: '确定',
		cancelButtonText: '取消',
		type: 'warning',
	})
		.then(async () => {
			await WmsApi().WhPageDelete(row.id)
				.then(function (res) {
					ElMessage.success('删除成功');
					getData(state.queryParams);
				})
		})
		.catch(() => {
			ElMessage({
				type: 'info',
				message: 'Delete canceled',
			})
		});
}

// 打开新增页面
const openAddOrg = () => {
	state.editPosTitle= '添加新仓库';
	editPosRef.value?.openDialog(state.ruleForm);
};

// 打开编辑页面
const openEdit = (row: any) => {
	state.editPosTitle = '编辑仓库';
	editPosRef.value?.openDialog(row);
};

const handleSizeChange = (val: any) => {
	state.queryParams.pageSize = val;
	state.queryParams.whNum = state.value?.whNum;
	state.queryParams.whName = state.value?.whName;
	getData(state.queryParams);
};

const handleCurrentChange = (newVal: any) => {
	state.queryParams.page = newVal;
	state.queryParams.whNum = state.value?.whNum;
	state.queryParams.whName = state.value?.whName;
	getData(state.queryParams);
};

</script>
<style lang="scss" scoped>
.custom-label {
	font-weight: bold;
}

.fl {
	width: 70%;
	margin: 20px 80px;
}

.radius {
	height: 24px;
	width: 300px;
	border: 1px solid var(--el-border-color);
	border-radius: 5px;
	background-color: #ddd;
	padding-left: 8px;
	color: #afabb9;
	background-color: #f5f7fa;
}
</style> -->

<template>
	<div class="sys-menu-container">
		<el-card shadow="hover" :body-style="{ paddingBottom: '0' }">
			<el-form :model="state.queryParams" ref="queryForm" :inline="true">
				<el-form-item label="菜单名称">
					<el-input v-model="state.queryParams.title" placeholder="菜单名称" clearable />
				</el-form-item>
				<el-form-item label="类型">
					<el-select v-model="state.queryParams.type" placeholder="类型" clearable>
						<el-option label="目录" :value="1" />
						<el-option label="菜单" :value="2" />
						<el-option label="按钮" :value="3" />
					</el-select>
				</el-form-item>
				<el-form-item>
					<el-button-group>
						<el-button type="primary" icon="ele-Search" @click="handleQuery" v-auth="'sysMenu:list'"> 查询 </el-button>
						<el-button icon="ele-Refresh" @click="resetQuery"> 重置 </el-button>
					</el-button-group>
				</el-form-item>
				<el-form-item>
					<el-button type="primary" icon="ele-Plus" @click="openAddMenu" v-auth="'sysMenu:add'"> 新增 </el-button>
				</el-form-item>
			</el-form>
		</el-card>

		<el-card class="full-table" shadow="hover" style="margin-top: 5px">
			<el-table :data="state.menuData" v-loading="state.loading" row-key="warehouseNum" :tree-props="{ children: 'children', hasChildren: 'hasChildren' }" border>
				<!-- <el-table-column label="菜单名称" header-align="center" show-overflow-tooltip>
					<template #default="scope">
						<SvgIcon :name="scope.row.icon" />
						<span class="ml10">{{ $t(scope.row.title) }}</span>
					</template>
				</el-table-column> -->
			
				<el-table-column prop="warehouseName" label="仓库名称" header-align="center" show-overflow-tooltip />
				<!-- <el-table-column prop="type" label="类型" align="center" show-overflow-tooltip /> -->
				<el-table-column label="类型" width="70" prop="type" align="center" show-overflow-tooltip>
					<template #default="scope">
						<el-tag type="warning" v-if="scope.row.type === 1">目录</el-tag>
						<el-tag v-else-if="scope.row.type === 2">菜单</el-tag>
						<el-tag type="info" v-else>按钮</el-tag>
					</template>
				</el-table-column>
				<el-table-column prop="order" label="排序" width="70" align="center" show-overflow-tooltip />
				<el-table-column label="状态" width="80" align="center" show-overflow-tooltip>
					<template #default="scope">
						<el-tag type="success" v-if="scope.row.status === 1">启用</el-tag>
						<el-tag type="danger" v-else>禁用</el-tag>
					</template>
				</el-table-column>

				<!-- <el-table-column label="修改记录" width="100" align="center" show-overflow-tooltip>
					<template #default="scope">
						<ModifyRecord :data="scope.row" />
					</template>
				</el-table-column> -->
				<el-table-column label="操作" width="140" fixed="right" align="center" show-overflow-tooltip>
					<template #default="scope">
						<el-button icon="ele-Edit" size="small" text type="primary" @click="openEditMenu(scope.row)" v-auth="'sysMenu:update'"> 编辑 </el-button>
						<el-button icon="ele-Delete" size="small" text type="danger" @click="delMenu(scope.row)" v-auth="'sysMenu:delete'"> 删除 </el-button>
					</template>
				</el-table-column>
			</el-table>
		</el-card>

		<EditMenu ref="editMenuRef" :title="state.editMenuTitle" :menuData="state.menuData" @handleQuery="handleQuery" />
	</div>
</template>

<script lang="ts" setup name="sysMenu">
import { onMounted, reactive, ref } from 'vue';
import { ElMessageBox, ElMessage } from 'element-plus';
import EditMenu from '/@/views/system/warehouse/component/editMenu.vue';


import { getAPI } from '/@/utils/axios-utils';
import { SysMenuApi } from '/@/api-services/api';
import { SysMenu } from '/@/api-services/models';

const editMenuRef = ref<InstanceType<typeof EditMenu>>();
const state = reactive({
	loading: false,
	menuData: [] as Array<SysMenu>,
	queryParams: {
		title: undefined,
		type: undefined,
	},
	editMenuTitle: '',
});

onMounted(async () => {
	handleQuery();
});

// 查询操作
const handleQuery = async () => {
	state.loading = true;
	
	state.menuData = [
	{
		"pid":11111111,
    "warehouseName": "利弗德",
    "warehouseNum": "12",
    "type":1,
    "order": 54,
    "status": 1,
	"id":8,
	"regionMaterielNum": "",
    "children": [{
		"id":9,
		"pid":1222222222222,
        "warehouseName": "B1",
        "warehouseNum": "78",
		"type": 2,
		"order": 4,
        "status": 1,
        "regionMaterielNum": "17"
    }]
},
{
	"id":18,
	"pid":222222222222,
    "warehouseName": "先临",
    "warehouseNum": "13",
    "type":1,
    "order": 55,
    "status": 1,
	"regionMaterielNum": "",
    "children": [{
		"id":19,
		"pid":2333333333333,
        "warehouseName": "线边仓",
        "warehouseNum": "79",
		"type": 2,
		"order": 4,
        "status": 1,
        "regionMaterielNum": "17"
    },
	{
		"id":20,
		"pid":244444444444,
        "warehouseName": "原料仓",
        "warehouseNum": "xl",
		"type": 2,
		"order": 5,
        "status": 1,
        "regionMaterielNum": "18"
    }
]
}
	]
	console.log(state.menuData);
	
	state.loading = false;
};

// 重置操作
const resetQuery = () => {
	state.queryParams.title = undefined;
	state.queryParams.type = undefined;
	handleQuery();
};

// 打开新增页面
const openAddMenu = () => {
	state.editMenuTitle = '添加菜单';
	editMenuRef.value?.openDialog({ type: 2, isHide: false, isKeepAlive: true, isAffix: false, isIframe: false, status: 1, orderNo: 100 });
};

// 打开编辑页面
const openEditMenu = (row: any) => {
	state.editMenuTitle = '编辑菜单';
	editMenuRef.value?.openDialog(row);
};

// 删除当前行
const delMenu = (row: any) => {
	ElMessageBox.confirm(`确定删除菜单：【${row.title}】?`, '提示', {
		confirmButtonText: '确定',
		cancelButtonText: '取消',
		type: 'warning',
	})
		.then(async () => {
			await getAPI(SysMenuApi).apiSysMenuDeletePost({ id: row.id });
			handleQuery();
			ElMessage.success('删除成功');
		})
		.catch(() => {});
};
</script>
